from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options

# 定义多个测试方法，在 main 中调用

# 设置浏览器、启动浏览器
def create_driver():
    options = Options()
    options.add_argument('--no-sandbox')
    options.add_experimental_option("detach", True)
    driver_edge = webdriver.Edge(options=options)
    driver_edge.maximize_window()
    return driver_edge


def fee_01():
    driver = create_driver()
    driver.get("http://course.recttech.cn/baggage-fee/")

    driver.find_element(By.ID, "weight").send_keys("28")
    driver.find_element(By.CSS_SELECTOR, "button").click()
    fee = driver.find_element(By.ID, "fee").get_attribute("value")

    assert fee == "0"

    sleep(1)
    driver.quit()


def fee_02():
    driver = create_driver()
    driver.get("http://course.recttech.cn/baggage-fee/")

    # 行李重量
    weight = driver.find_element(By.ID, "weight")
    weight.clear()
    weight.send_keys("32")

    # 乘客仓位：头等舱
    cabins = driver.find_elements(By.NAME, "cabin")
    cabins[0].click()
    # 乘客类型：国内乘客
    passenger_types = driver.find_elements(By.NAME, "passengerType")
    passenger_types[0].click()
    # 是否残疾：否
    disabled = driver.find_element(By.ID, "disabled")
    if disabled.is_selected():
        disabled.click()

    driver.find_element(By.CSS_SELECTOR, "button").click()

    fee = driver.find_element(By.ID, "fee").get_attribute("value")

    assert fee == "8"

    sleep(1)
    driver.quit()


if __name__ == '__main__':
    fee_01()
    fee_02()
